package kr.saeildamil.androidstudty.ch08;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;

public class HandleEvent extends Activity implements View.OnTouchListener{
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//MyView mv = new MyView(this);
		//setContentView(mv);
		View v = new View(this);
		v.setOnTouchListener(this);
		setContentView(v);
	}//end of onCreate
	
	@Override
	public boolean onTouch(View v, MotionEvent event) {
		if (event.getAction()==MotionEvent.ACTION_DOWN){
			Toast.makeText(this, "Point " + event.getX() + ", " + event.getY() + " ACTION_DOWN", Toast.LENGTH_SHORT).show();
			return true;
		}else if (event.getAction()==MotionEvent.ACTION_UP){
			Toast.makeText(this, "ACTION_UP", Toast.LENGTH_SHORT).show();
			return true;
		}
		return false;
	}//end of method onTouch

/*	TouchListenerClass listener = new TouchListenerClass();
	
	public class TouchListenerClass implements View.OnTouchListener{
		@Override
		public boolean onTouch(View v, MotionEvent event) {
			if (event.getAction()==MotionEvent.ACTION_DOWN){
				Toast.makeText(HandleEvent.this, "Point " + event.getX() + ", " + event.getY() + " ACTION_DOWN", Toast.LENGTH_SHORT).show();
				return true;
			}else if (event.getAction()==MotionEvent.ACTION_UP){
				Toast.makeText(HandleEvent.this, "ACTION_UP", Toast.LENGTH_SHORT).show();
				return true;
			}
			return false;
		}//end of method onTouch
	}//end of class TouchListenerClass
	
	public class MyView extends View{

		public MyView(Context context) {
			super(context);
		}

		@Override
		public boolean onTouchEvent(MotionEvent event) {
			super.onTouchEvent(event);
			float x = event.getX();
			float y = event.getY();
			
			if (event.getAction()==MotionEvent.ACTION_DOWN){
				Toast.makeText(HandleEvent.this, "Point " + x + ", " + y + " ACTION_DOWN", Toast.LENGTH_SHORT).show();
				return true;
			}else if (event.getAction()==MotionEvent.ACTION_UP){
				Toast.makeText(HandleEvent.this, "ACTION_UP", Toast.LENGTH_SHORT).show();
				return true;
			}
			return false;
		}//end of method onTouchEvent
		
		
	}//end of class MyView
*/

}





